<script lang="ts" setup>
import useStore from '@/store'
import { useRoute } from 'vue-router'
import { storeToRefs } from 'pinia'
import GoodsImage from './components/goods-image.vue'
import GoodsSales from './components/goods-sales.vue'
import GoodName from './components/goods-name.vue'
import GoodsRelevant from './components/goods-relevant.vue'
import GoodsSku from './components/goods-sku.vue'
import { SkusItem } from '@/types/data'
import GoodsDetail from './components/goods-detail.vue'
import GoodsHot from './components/goods-hot.vue'
import { ref } from 'vue'
const route = useRoute()
const { goods } = useStore()
const { goodsInfo } = storeToRefs(goods)
goods.getGoods(route.params.id as string)
const getSelected = (sku: SkusItem) => {
  goodsInfo.value.inventory = sku.inventory
  goodsInfo.value.price = sku.price
  goodsInfo.value.oldPrice = sku.oldPrice
  console.log(sku)
}
// 商品数量
const num = ref(3)
</script>
<template>
  <div class="xtx-goods-page" v-if="goodsInfo.id">
    <div class="container">
      <!-- 面包屑 -->
      <XtxBreadcrumb>
        <XtxBreadcrumbItem to="/">首页</XtxBreadcrumbItem>
        <XtxBreadcrumbItem :to="`/category/${goodsInfo.categories[1].id}`">{{
          goodsInfo.categories[1].name
        }}</XtxBreadcrumbItem>
        <XtxBreadcrumbItem
          :to="`/category/sub/${goodsInfo.categories[0].id}`"
          >{{ goodsInfo.categories[0].name }}</XtxBreadcrumbItem
        >
        <XtxBreadcrumbItem>{{ goodsInfo.name }}</XtxBreadcrumbItem>
      </XtxBreadcrumb>
      <!-- 商品信息 -->
      <div class="goods-info">
        <div class="media">
          <GoodsImage :pictures="goodsInfo.mainPictures"></GoodsImage>
          <GoodsSales></GoodsSales>
        </div>
        <div class="spec">
          <GoodName :goodsInfo="goodsInfo"></GoodName>
          <GoodsSku
            :goodsInfo="goodsInfo"
            @getSelected="getSelected"
          ></GoodsSku>
          <!-- <XtxNumbox
            :isShowLabel="false"
            :modelValue="num"
            @update:modelValue="num = $event"
          >
            商品数
          </XtxNumbox> -->
          <XtxNumbox v-model="num">
            商品数
          </XtxNumbox>
          <XtxButton size="large" type="primary" style="margin-top:40px;"
            >加入购物车</XtxButton
          >
        </div>
      </div>
      <!-- 同类商品推荐 -->
      <GoodsRelevant></GoodsRelevant>
      <!-- 商品详情 -->
      <div class="goods-footer">
        <div class="goods-article">
          <!-- 商品+评价 -->
          <div class="goods-tabs">
            <GoodsDetail :goods="goodsInfo"></GoodsDetail>
          </div>
        </div>
        <!-- 24热榜+专题推荐 -->
        <div class="goods-aside">
          <GoodsHot :type="1"></GoodsHot>
          <GoodsHot :type="2"></GoodsHot>
          <GoodsHot :type="3"></GoodsHot>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="less">
.goods-info {
  min-height: 600px;
  background: #fff;
  display: flex;
  .media {
    width: 580px;
    height: 600px;
    padding: 30px 50px;
  }
  .spec {
    flex: 1;
    padding: 30px 30px 30px 0;
  }
}
.goods-footer {
  display: flex;
  margin-top: 20px;
  .goods-article {
    width: 940px;
    margin-right: 20px;
  }
  .goods-aside {
    width: 280px;
    min-height: 1000px;
  }
}
.goods-tabs {
  min-height: 600px;
  background: #fff;
}
.goods-warn {
  min-height: 600px;
  background: #fff;
  margin-top: 20px;
}
</style>
